package view.Validator;

import javafx.scene.control.Control;
import javafx.scene.control.TextField;
import model.Configuration;

import org.controlsfx.validation.ValidationResult;
import org.controlsfx.validation.Validator;

public class PasswordValidator extends NameValidator implements Validator<String>{

	@Override
	public ValidationResult apply(Control t, String u) {
		ValidationResult res = new ValidationResult();
		res.addAll(super.apply(t, u).getMessages());
		if (t instanceof TextField) {
			res.addErrorIf(
					t,
					"Das Passwort muss mindestens die Laenge " + Configuration.MINPWLENGTH + " haben.",
					 0 < ((TextField) t).lengthProperty().get() && ((TextField) t).lengthProperty().get() < Configuration.MINPWLENGTH);
		}
		return res;
	}
}
